#include <cstdlib>
#include <iostream>
using namespace std;




class String{
      public:
             String():m_str(NULL){}
             explicit String(const char* str){
                      if(!str){
                              str="";
                      }
                      m_str = new char[strlen(str)+1];
                      strcpy(m_str, str);
             }
             String(const String& s){
                          m_str = new char[strlen(s.m_str)+1];
                          strcpy(m_str, s.m_str);
             }
             String& operator= (const String& r){
                          if(this == &r)
                                  return *this;
                          m_str = new char[strlen(r.m_str)+1];
                          strcpy(m_str, r.m_str);
                          return *this;
             }
             ~String(){
                       if(m_str){
                                 delete []m_str;
                       }                       
             }
             operator const char* (){return m_str;}
      private:
              char* m_str;
};


int main(int argc, char *argv[])
{
    String str("abcdefg");
    cout<<str<<endl;
    String str1, str2, str3;
    str1=str2=str3=str;
    String str4(str1);

    cout<<str1<<endl;
    cout<<str2<<endl;
    cout<<str3<<endl;
    cout<<str4<<endl;    

    String str5(NULL);
    cout<<str5<<endl;    
    String str6=str5;

    system("PAUSE");
    return EXIT_SUCCESS;
}
